package com.antg;

/**
 * @Description:
 * @Author 子兔Antg
 * @Date 2021/11/15
 **/
public class Code_7 {
    public static void main(String[] args) {
        int a = 1534236469;
        System.out.println(reverse2(a));
    }
    public static int reverse(int x) {
        boolean lessZero = false;
        if(x<0){
            lessZero = true;
            x = -x;
        }
        //转换成字符串
        String temp = Integer.toString(x);
        //反转字符串
        StringBuilder stringBuilder = new StringBuilder();
        boolean flag = true;
        for(int i = 0;i<temp.length();i++){
            char e = temp.charAt(temp.length()-1-i);

            if(e == '0'&&flag){
                continue;
            }
            stringBuilder.append(e);
            flag = false;
        }
        if(stringBuilder.length()==0){
            return 0;
        }
        int res;
        try{
            res = lessZero?-Integer.parseInt(stringBuilder.toString()):Integer.parseInt(stringBuilder.toString());
        }catch (Exception e){
            return 0;
        }
        return res;
    }

    public static int reverse2(int x) {
        long n = 0;
        while(x != 0) {
            n = n*10 + x%10;
            x = x/10;
        }
        return (int)n==n? (int)n:0;
    }
}
